package com.zhongjian.technologycal.mall.splash;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.activity.MainActivity;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.utils.AppTools;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 闪屏页面
 */

public class SplashActivity extends BaseActivity {
    private boolean isIn;
    @BindView(R.id.splash_iv_pic)
    ImageView mIvPic;
    @BindView(R.id.splash_tv_jump)
    TextView mTvJump;
    @BindView(R.id.splash_iv_defult_pic)
    ImageView mIvDefultPic;
    @BindView(R.id.splash_imageView3)
    ImageView splash_imageView3;
    @BindView(R.id.splash_imageView4)
    ImageView splash_imageView4;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_splash;
    }
    @Override
    protected void beforeInit() {
        super.beforeInit();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
//        StatusBarUtil.setTranslucent(this,0);
//        StatusBarUtil.setMiuiStatusBarDarkMode(this,true);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        AppTools.foundDeviceAnim(splash_imageView3);
        AppTools.foundDeviceAnim(splash_imageView4);

//        int i = new Random().nextInt(ConstantsImageUrl.TRANSITION_URLS.length);
//
////        // 先显示默认图
//        mIvDefultPic.setImageDrawable(getResources().getDrawable(R.drawable.img_transition_default));
//        Glide.with(this)
//                .load(ConstantsImageUrl.TRANSITION_URLS[i])
//                .placeholder(R.drawable.img_transition_default)
//                .error(R.drawable.img_transition_default)
//                .into(mIvPic);
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                mIvDefultPic.setVisibility(View.GONE);
//            }
//        }, 1500);
//
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                toMainActivity();
            }
        }, 3500);
    }



    @Override
    public boolean isSupportSwipeBack() {
        return false;
    }



    /**
     * 跳转到主页面
     */
    private void toMainActivity() {
        if (isIn) {
            return;
        }
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
        isIn = true;
    }
    @OnClick(R.id.splash_tv_jump)
    public void onClick() {
        toMainActivity();
    }
    @Override
    public void initPresenter() {

    }


}
